/*
 * Copyright (c) 2020 - present, Inspur Genersoft Co., Ltd.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.inspur.edp.bff.designtime.generator.core.rtgen.managergenerator.mgrinterface;

import com.inspur.edp.bff.api.manager.IFSManager;
import com.inspur.edp.bff.designtime.generator.core.rtgen.managergenerator.FSMgrGeneratorContext;
import com.inspur.edp.caf.generator.baseInfo.TypeInfo;
import com.inspur.edp.caf.generator.item.InterfaceGenerator;
import com.inspur.edp.caf.generator.item.InterfaceGeneratorContext;
import com.inspur.edp.cef.gencommon.MediateType;
import com.inspur.edp.cef.generator.repository.common.IntermediateType;
import lombok.var;
import org.eclipse.jdt.core.dom.Modifier;

import java.util.ArrayList;

public class FSMgrInterfaceGenerator extends InterfaceGenerator {
    private FSMgrGeneratorContext mgrGenContext;

    public FSMgrInterfaceGenerator(FSMgrGeneratorContext mgrGenContext) {
        super(mgrGenContext.getFSGeneratorContext().getCompilationUnitInfo());
        this.mgrGenContext = mgrGenContext;
    }

    protected FSMgrInterfaceGenContext getContext() {
        return (FSMgrInterfaceGenContext) ((super.getContext() instanceof FSMgrInterfaceGenContext) ? super.getContext() : null);
    }

    @Override
    protected ArrayList<TypeInfo> addParentInterfaces() {

        var types = super.addParentInterfaces();
        if (types == null) {
            types = new ArrayList<TypeInfo>();
        }

        types.add(new TypeInfo(mgrGenContext.getFSGeneratorContext().getVmGenContext().getMgrInterfaceType().getFullName()));
        types.add(new TypeInfo(mgrGenContext.getFSGeneratorContext().getVmGenContext().getMgrAllInterfaceType().getClassName()));

//        types.add(new TypeInfo(mgrGenContext.getFSGeneratorContext().getParentType().getInterfaceType()));
        types.add(new TypeInfo(IFSManager.class));

        return types;
    }

    @Override
    protected InterfaceGeneratorContext createInterfaceItemContext() {
        FSMgrInterfaceGenContext context = new FSMgrInterfaceGenContext(mgrGenContext);
        mgrGenContext.setInterfaceContext(context);
        return context;
    }

    @Override
    protected ArrayList<Modifier.ModifierKeyword> getAccessModifier() {
        return new ArrayList<Modifier.ModifierKeyword>(
                java.util.Arrays.asList(new Modifier.ModifierKeyword[]{Modifier.ModifierKeyword.PUBLIC_KEYWORD})
        );
    }

    @Override
    protected void afterGenerate() {
        super.afterGenerate();
        getContext().getMgrGenContext().getFSGeneratorContext().getFsIntermediateTypeInfo()
                .setFSMgrInterfaceType(new IntermediateType(getName(), getNameSpace()));

    }


    @Override
    protected String getName() {
        return getContext().getInterfaceName();
    }

    protected String getNameSpace() {
        return getContext().getInterfaceNamespace();
    }
}
